var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		data: [],
		currentActiveIndex: 0,
		animation: true
	},
	_onLoad: function () {
		var that = this
		$.get('shop/category', {}, function (res) {
			//计算每个高度
			var harr = [];
			var clientwidth = wx.getSystemInfoSync().windowWidth;
			var data = res.data;
			for (var i = 0; i < data.length; i++) {
				var child = data[i].child;
				harr.push((Math.ceil(child.length / 3) * 196) / 750 * clientwidth);
			}
			res.harr = harr;
			console.log(harr)
			that.setData(res);
		})
	},
	clickRootItem: function (t) {
		var e = t.currentTarget.dataset;
		this.setData({ scrollToViewId: 'detail-' + e.rootItemId, currentActiveIndex: e.rootItemIndex })
		console.log(t)
		//rootListScrollTop
	},
	gotoCatproductPage: function (t) {
		var e = t.currentTarget.dataset;
		$.goto('/pages/shop/prolist?cid=' + e.id);
	},
	scroll: function (e) {
		var scrollTop = e.detail.scrollTop
		var harr = this.data.harr
		var countH = 0
		for (var i = 0; i < harr.length; i++) {
			if (scrollTop >= countH && scrollTop < countH + harr[i]) {
				this.setData({ currentActiveIndex: i })
				break;
			}
			countH += harr[i]
		}
		console.log(i)
	}
}));